// pages/chongzhi/chongzhi.js
Page({
    data: { 
    inputAmount: "", // 用户手动输入的充值金额
    balance: 0, // 初始余额，可根据实际情况从后台获取或设置其他初始值
    },
    // 选择预设充值金额
    selectAmount(e) {
      const amount = Number(e.currentTarget.dataset.amount);
      this.setData({
        inputAmount: amount
      });
    },
    // 处理手动输入金额的变化
    onInputAmount(e) {
      const amount = Number(e.detail.value);
      if (!isNaN(amount)) {
        this.setData({
          inputAmount: amount
        });
      }
    },
    
    // 充值按钮点击事件
    recharge() {
      const rechargeAmount = this.data.inputAmount;
      if (rechargeAmount > 0) {
        const newBalance = this.data.balance + rechargeAmount;
        this.setData({
          balance: newBalance
        });
        wx.showToast({
          title: '充值成功',
          icon: 'success',
          duration: 2000
        });
      } else {
        wx.showToast({
          title: '请输入正确的充值金额',
          icon: 'none',
          duration: 2000
        });
      }
    }
  })